import java.io.*;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;

public class Maintest {
    public static void main(String[] args){
        int zs=0;
        char sd[]={'a','b','c','d','e','f','g','h','i','j'
                    ,'k','l','m','n','o','p','q','r','s',
                    't','u','v','w','x','y','z'};
        Map<Character, Integer> m = new HashMap<>();
        for (int i=0;i<sd.length;i++){
            m.put(sd[i],0);
        }
        File f = new File("F:\\Chrome Download\\nsise-level-18-personal-project-master\\level-18-personal-project\\Gone_with_the_wind.txt");
        try{
            BufferedInputStream fis = new BufferedInputStream(new FileInputStream(f));
            int b;
            while((b=fis.read())!=-1){
                char mdd =(char)b;

                if (mdd>='a'&&mdd<='z'){

                    zs++;

                }
                for(char s:m.keySet()){
                    if (s==mdd){
                        m.put(s,m.get(s)+1);
                        continue;
                    }
                }

            }
            System.out.println(f.length());
            fis.close();
        }catch (IOException e) {
            e.printStackTrace();
        }
        int he =0;
        System.out.println("字母总数:"+zs);
        NumberFormat numberFormat = NumberFormat.getInstance();

        // 设置精确到小数点后2位
        numberFormat.setMaximumFractionDigits(2);

        double ss=0;
        for(char s:m.keySet()){
            String result = numberFormat.format((float) m.get(s)/ (float)zs * 100);
            System.out.println("字母"+s+"\t"+"占比:"+result+"%");
            ss=ss+Double.parseDouble(result);
            }
    }
    }

